package com.example.mytestdemo.extensions

import android.content.Intent
import androidx.fragment.app.Fragment

class ForResultFragment : Fragment() {

    private var callback: Callback? = null

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        callback?.onActivityResult(requestCode, resultCode, data)
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        callback?.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }

    fun setCallback(callback: Callback) {
        this.callback = callback
    }

    open class Callback {
        open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

        }

        open fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

        }
    }
}